package br.com.atid.model.graphicalNetElements
{
	import mx.collections.ArrayCollection;

	public class GraphicalNet
	{
		private var _graphicalElements:ArrayCollection=new ArrayCollection();
		private var _arcs:ArrayCollection=new ArrayCollection();
		private var _collisionGroup:ArrayCollection=new ArrayCollection;

		public function GraphicalNet()
		{
		}

		public function addGraphicalElements(graphicalElement:IGraphicalNetElement, elementName:String = null):void
		{
			setNewId(graphicalElement, elementName);
			this._graphicalElements.addItem(graphicalElement);
		}

		public function addCollisionElements(collisionElement:Object):void
		{
			this._collisionGroup.addItem(collisionElement);
		}

		public function traceGraphicalElements():void
		{
			for each (var ge:Object in _graphicalElements)
			{
				trace(ge.id);
				trace(ge.name);
			}
		}

		public function setNewId(newGraphicalElement:IGraphicalNetElement, elementName:String=null):void
		{
			var quantity:int=0;
			for each (var ge:IGraphicalNetElement in _graphicalElements)
			{
				if (ge.type == newGraphicalElement.type)
				{
					quantity++;
				}
			}

			if (quantity == 0)
			{
				newGraphicalElement.id=newGraphicalElement.type + '1';
				if (elementName != null)
				{
					newGraphicalElement.name=elementName;
				}
				else
				{
					newGraphicalElement.name=newGraphicalElement.type + ' 1';
				}
			}
			else
			{
				newGraphicalElement.id=newGraphicalElement.type + String(quantity + 1);
				if (elementName != null)
				{
					newGraphicalElement.name=elementName;
				} else {
					newGraphicalElement.name=newGraphicalElement.type + ' ' + String(quantity + 1);
				}
			}
		}

		public function get collisionGroup():ArrayCollection
		{
			return _collisionGroup;
		}

	}
}
